package com.ylyq.ylxx.model.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @ClassName ChatData
 * @Description TODO
 * @Author xiaweichao
 * @Date 2020/10/21 15:41
 * @Version 1.0
 */
@NoArgsConstructor
@Data
public class ChatData {

    private List<ChatDataBean> chatData;

    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    public static class ChatDataBean {
        /**
         * question : hi
         * anser : hello
         */

        private String question;
        private String anser;

        @Override
        public boolean equals(Object obj) {
            if(this == obj){
                return true;//地址相等
            }

            if(obj == null){
                return false;//非空性：对于任意非空引用x，x.equals(null)应该返回false。
            }

            if(obj instanceof ChatDataBean){
                ChatDataBean other = (ChatDataBean) obj;
                //需要比较的字段相等，则这两个对象相等
                if(equalsStr(this.question, other.question)&& equalsStr(this.anser, other.anser)){
                    return true;
                }
            }

            return false;
        }

        private boolean equalsStr(String str1, String str2){
            if(StringUtils.isEmpty(str1) && StringUtils.isEmpty(str2)){
                return true;
            }
            if(!StringUtils.isEmpty(str1) && str1.equals(str2)){
                return true;
            }
            return false;
        }

        @Override
        public int hashCode() {
            int result =(question == null ? 0 : question.hashCode()) + (anser == null ? 0 : anser.hashCode());
            return result;
        }
    }
}
